package com.mall.server.service;

import com.mall.commons.exceotion.BusinessException;
import com.mall.commons.exceotion.ErrorResult;
import com.mall.dubbo.api.ResourceCategoryApi;
import com.tanhua.model.domain.UmsResourceCategory;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResourceCategoryService {

    @DubboReference
    private ResourceCategoryApi resourceCategoryApi;

    //查询所有后台资源分类
    public List<UmsResourceCategory> listAll() {

        List<UmsResourceCategory> umsResource = resourceCategoryApi.listAll();

        if (umsResource == null) {

            throw new BusinessException(ErrorResult.emptyError());
        }

        return umsResource;
    }

    //根据ID删除后台资源
    public void deletes(Integer id) {
        boolean exits = resourceCategoryApi.deletes(id);
        if (!exits) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }

    //添加后台资源分类
    public void create(UmsResourceCategory umsResourceCategory) {
        //添加成功返回true
        boolean exits = resourceCategoryApi.create(umsResourceCategory);
        if (!exits) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }

    //修改后台资源分类
    public void updates(UmsResourceCategory umsResourceCategory, Integer id) {
        //修改成功返回true
        boolean exits = resourceCategoryApi.updates(umsResourceCategory,id);
        if (!exits) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }
}
